/*
Copyright 2007 Nathan Baker

This file is part of XAliens.

XAliens is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

XAliens is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with XAliens.  If not, see <http://www.gnu.org/licenses/>.
 */

package sprites;

import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import utils.BoundsRect;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Vector;

public class EnemyController {
    private Vector<EnemyShip> mEnemies = new Vector<EnemyShip>();
    private Vector<BufferedImage> mSpriteImages = new Vector<BufferedImage>();
    private BoundsRect mBounds;

    public EnemyController(BufferedImage spriteImage, BoundsRect bounds) {
        mSpriteImages.add(spriteImage);
        mBounds = bounds;
    }

    /**
     * Adds one enemy to the collection.
     */
    public void addEnemy() {
        mEnemies.add(new EnemyShip(mSpriteImages.get(0), mBounds));
    }

    /**
     * Adds a specified number of enemies to the collection.
     *
     * @param numToAdd The number of enemies to add.
     */
    public void addEnemies(int numToAdd) {
        for (int i = 0; i < numToAdd; i++) {
            mEnemies.add(new EnemyShip(mSpriteImages.get(0), mBounds));
        }
    }

    /**
     * Removes an enemy at index.
     *
     * @param index The index of EnemyShip to remove.
     */
    public void removeEnemy(int index) {
        if (index > mEnemies.size() - 1)
            throw new IndexOutOfBoundsException();
        mEnemies.remove(index);
    }

    /**
     * Remove all enemies from the collection
     */
    public void removeAllEnemies() {
        mEnemies.removeAllElements();
    }

    /**
     * Checks if a rectangle intersects any EnemyShip in the collection. Returns
     * the index of the EnemyShip that intersects.
     *
     * @param rct The Rectangle to check for collision.
     * @return The index of the EnemyShip that intersected with rct. -1 if no
     *         collision occurred.
     */
    public int intersectsEnemy(Rectangle rct) {
        for (int i = 0; i <= mEnemies.size() - 1; i++) {
            if (mEnemies.get(i).intersectsWith(rct))
                return i;
        }
        return -1;
    }

    /**
     * Sets the location of an EnemyShip at index.
     *
     * @param index The index of EnemyShip to set the location of.
     * @param p     The point to set the location to.
     */
    public void setLocation(int index, Point p) {
        throw new NotImplementedException();
    }
}
